package com.kfm.util;

import java.lang.reflect.Field;
import java.util.Map;

public class BeanUtil {

    public static <T> void populate(T t, Map map){
        // 获取字节码对象
        Class<?> aClass = t.getClass();
        // 获取所有的属性
        Field[] declaredFields = aClass.getDeclaredFields();

//        PropertyDescriptor propertyDescriptor = null;

        // 遍历 TODO(模拟操作，取第一个字段)
        Field declaredField = declaredFields[0];
        Object value = map.get(declaredField.getName());

        declaredField.setAccessible(true);
        try {
            declaredField.set(t, value);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
